package com.tianchi.lexiang.background.util;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.tianchi.lexiang.util.DBOperator;

public class PwdSettingUtil {

	private static final String TAG = "PwdSettingUtil";
	private static final PwdSettingUtil instence = new PwdSettingUtil();
	private SQLiteDatabase db = DBOperator.getInstance().getConnection();

	public PwdSettingUtil() {

	}

	public static PwdSettingUtil getInstence() {
		return instence;
	}

	public boolean changePassword(String pwd) {
		boolean isSuccess = true;
		ContentValues values = new ContentValues();
		String sql = "select USER_PWD from T_BDSM_USERS where USER_POWER=" + 1;
		Cursor mCursor = db.rawQuery(sql, null);
		mCursor.moveToFirst();
		Log.d(TAG, "[mCursor]...." + mCursor.getString(0));
		if (mCursor.getString(0).equals(pwd)) {
			values.put("USER_PWD", "888888");
		} else if (pwd.length() > 6 || pwd.length() <= 0) {
			return false;
		} else {
			values.put("USER_PWD", pwd);
		}
		try {
			isSuccess = db.update("T_BDSM_USERS", values, "USER_POWER=" + 0,
					null) > 0 ? true : false;

		} catch (Exception e) {
			Log.d(TAG, e.toString());
			isSuccess = false;
		}
		return isSuccess;
	}

}
